package org.diy.traffic.sources;

import java.util.HashMap;
import java.util.logging.Level;

import org.diy.traffic.util.TLog;


public class TrafficComSource extends RSSFeedSource {

	private static String sourceType = "TRAFFICCOM_SOURCE";
	
	public TrafficComSource(String cityName) {
		super(sourceType + "_" + cityName.toLowerCase(), 
				"http://cityrss.traffic.com/feeds/rss_" + cityName.toLowerCase());
	}

	public static TrafficComSource createFromConfigData(HashMap<String, String> configParams) throws TrafficSourceException {
		String cityName = configParams.get("cityName");
		if (cityName == null) {
			TLog.log(Level.SEVERE, "TrafficComSource requires a 'cityName' parameter for configuration! None provided.");
			return null;
		}
		
		return new TrafficComSource(cityName);
	}
	
	@Override
	public String processUpdateData(String update) {
		String processed;
		try {
			processed = update.substring(0, update.indexOf(":"));
		} catch (IndexOutOfBoundsException e) {
			processed = update;
		}
		
		return processed;
	}
	
	
}
